<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        //作用域链
        var num = 10;

        function fn() { //外部函数  作用域中的作用域
            var num = 20;

            function fun() { //内部函数
                console.log(num); //可访问外部函数的变量
                //先查找上一级 查到就用 没查到就再到上一级
            }
            fun();
        }
        fn();

        // 案例1 结果123
        function f1() {
            var num1 = 123;

            function f2() {
                console.log(num1);
            }
            f2();
        }
        var num1 = 456;
        f1(); //123

        //案例2 结果 4 22
        var a = 1;

        function fn3() {
            var a = 2;
            var b = '22';
            fn4();

            function fn4() {
                var a = 3;
                fn5();

                function fn5() {
                    var a = 4;
                    console.log(a); //4
                    console.log(b); //22
                }
            }
        }
        fn3();


        // function text() {
        //     var a = b = c = 9;
        // }
        // console.log(a);
        // console.log(b);
        // console.log(c);
    </script>
</head>

<body>

</body>

</html>